import 'dart:convert';

ChartsInfoData messageFilesDataFromJson(String str) => ChartsInfoData.fromJson(json.decode(str));

String messageFilesDataToJson(ChartsInfoData data) => json.encode(data.toJson());

// To parse this JSON data, do
//
// final messageFilesData = messageFilesDataFromJson(jsonString);

///
/// 图表📈 信息模型【柱状图📊、 饼状图】
///
class ChartsInfoData {
  final String? type;
  final List<ChartsCategoryModel> data;
  final String? axisXTitle;
  final String? axisYTitle;

  ChartsInfoData({
    this.type,
    this.data = const [],
    this.axisXTitle,
    this.axisYTitle,
  });

  factory ChartsInfoData.fromJson(Map<String, dynamic> json) => ChartsInfoData(
        type: json["type"],
        data: json["data"] == null ? [] : List<ChartsCategoryModel>.from(json["data"].map((x) => ChartsCategoryModel.fromJson(x))),
        axisXTitle: json["axisXTitle"],
        axisYTitle: json["axisYTitle"],
      );

  Map<String, dynamic> toJson() => {
        "type": type,
        "data": List<dynamic>.from(data.map((x) => x.toJson())),
        "axisXTitle": axisXTitle,
        "axisYTitle": axisYTitle,
      };
}

///
/// 图表分类数据模型
///
class ChartsCategoryModel {
  final String? category;
  final int? value;
  final int? color;

  ChartsCategoryModel({
    this.category,
    this.value,
    this.color,
  });

  factory ChartsCategoryModel.fromJson(Map<String, dynamic> json) => ChartsCategoryModel(
        category: json["category"],
        value: json["value"],
        color: json['color'],
      );

  Map<String, dynamic> toJson() => {
        "category": category,
        "value": value,
      };
}

///
/// 图表类型
///
enum ChartsType {
  colum(type: 'column'),
  pie(type: 'pie');

  final String type;

  const ChartsType({
    required this.type,
  });
}
